home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
apps
/
xconf
/
ConfList.c++
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
10KB
|
350 lines
/*
* Copyright 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
//
// Class: ConfList
// Base Classes: none
// Author: Jesse Rendleman (jesse@sgi.com)
//
// unix includes
#include <sys/types.h>
#include <malloc.h>
// motif includes
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/List.h>
#include <Xm/Label.h>
#include <Xm/SelectioB.h>
// conf includes
#include "ConfDoc.h"
ConfList::ConfList()
{
_numItems = 0;
}
ConfList::~ConfList() {}
void ConfList::init(Widget parent, char *title)
{
char buf[16];
// build the widgets
strcpy(buf, title);
strcat(buf, "Dialog");
_dWidget = XmCreateSelectionDialog(parent, buf, NULL, 0);
XtAddCallback(_dWidget, XmNokCallback,
(XtCallbackProc)&ConfList::okCB,
(XtPointer)this);
XtAddCallback(_dWidget, XmNcancelCallback,
(XtCallbackProc)&ConfList::cancelCB,
(XtPointer)this);
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_TEXT));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_SELECTION_LABEL));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_APPLY_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_HELP_BUTTON));
_listWidget = XmSelectionBoxGetChild(_dWidget, XmDIALOG_LIST);
// kludgy, have this passed in later.. (groups, is a multiple select list)
if(!strcmp(title, "groups")) {
Arg args[1];
XtSetArg(args[0], XmNselectionPolicy, XmMULTIPLE_SELECT);
XtSetValues(_listWidget, args, 1);
}
}
void ConfList::open()
{
XtManageChild(_dWidget);
}
void ConfList::clear()
{
XmListDeleteAllItems(_listWidget);
}
void ConfList::okCB(Widget, XtPointer clientData, XtPointer)
{
ConfList* obj = (ConfList*)clientData;
XtUnmanageChild(obj->_dWidget);
}
void ConfList::cancelCB(Widget, XtPointer clientData, XtPointer)
{
ConfList* obj = (ConfList*)clientData;
XtUnmanageChild(obj->_dWidget);
}
Boolean ConfList::add(char *item, Boolean select)
{
XmString itemString = XmStringCreate(item, XmSTRING_DEFAULT_CHARSET);
_numItems++;
XmListAddItem(_listWidget, itemString, _numItems);
if(select) {
strcpy(_item, item);
XmListSelectItem(_listWidget, itemString, FALSE);
}
XmStringFree(itemString);
return(TRUE);
}
Boolean ConfList::select(char *item)
{
if(find(item)) {
XmString itemString = XmStringCreate(item, XmSTRING_DEFAULT_CHARSET);
XmListDeselectItem(_listWidget, itemString);
XmListSelectItem(_listWidget, itemString, FALSE);
XmStringFree(itemString);
return(TRUE);
}
else {
return(FALSE);
}
}
Boolean ConfList::remove(char *item)
{
XmString itemString = XmStringCreate(item, XmSTRING_DEFAULT_CHARSET);
if(XmListItemExists(_listWidget, itemString)) {
XmListDeleteItem(_listWidget, itemString);
_numItems--;
XmStringFree(itemString);
return(TRUE);
}
XmStringFree(itemString);
return(FALSE);
}
Boolean ConfList::find(char *item)
{
XmString itemString = XmStringCreate(item, XmSTRING_DEFAULT_CHARSET);
if(XmListItemExists(_listWidget, itemString)) {
XmStringFree(itemString);
return(TRUE);
}
XmStringFree(itemString);
return(FALSE);
}
Boolean ConfList::findSelected(char *item)
{
XmString itemString = XmStringCreate(item, XmSTRING_DEFAULT_CHARSET);
int pos = XmListItemPos(_listWidget, itemString);
int* pos_list;
int pos_cnt;
if(!XmListGetSelectedPos(_listWidget, &pos_list, &pos_cnt)) {
XmStringFree(itemString);
return(FALSE);
}
for(int n=0; n<pos_cnt; n++) {
if(*pos_list == pos) {
free(pos_list);
XmStringFree(itemString);
return(TRUE);
}
pos_list++;
}
free(pos_list);
XmStringFree(itemString);
return(FALSE);
}
///////////////////////////////////////////////////////////////////////////////
// GroupList functions
///////////////////////////////////////////////////////////////////////////////
GroupList::GroupList()
{
_numItems = 0;
}
GroupList::~GroupList() {}
void GroupList::init(Widget parent, char *title, ConfDoc* confdoc)
{
char buf[16];
// set the pointer to the ConfDoc
_confdoc = confdoc;
// build the widgets
strcpy(buf, title);
strcat(buf, "Dialog");
_dWidget = XmCreateSelectionDialog(parent, buf, NULL, 0);
XtAddCallback(_dWidget, XmNokCallback,
(XtCallbackProc)&GroupList::okCB,
(XtPointer)this);
XtAddCallback(_dWidget, XmNcancelCallback,
(XtCallbackProc)&GroupList::cancelCB,
(XtPointer)this);
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_TEXT));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_SELECTION_LABEL));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_APPLY_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_HELP_BUTTON));
_listWidget = XmSelectionBoxGetChild(_dWidget, XmDIALOG_LIST);
}
void GroupList::okCB(Widget, XtPointer clientData, XtPointer callData)
{
GroupList* obj = (GroupList*)clientData;
XmSelectionBoxCallbackStruct* cd = (XmSelectionBoxCallbackStruct*)callData;
// only try to switch groups if a new group was selected
char* gp;
XmStringGetLtoR(cd->value, XmSTRING_DEFAULT_CHARSET, &gp);
if(strlen(gp) && strcmp(obj->_item, gp)) {
strcpy(obj->_item, gp);
char new_group[33];
strcpy(new_group, ":g ");
strcat(new_group, obj->_item);
obj->_confdoc->setGroup(new_group);
}
XtUnmanageChild(obj->_dWidget);
}
///////////////////////////////////////////////////////////////////////////////
// PrivateList functions
///////////////////////////////////////////////////////////////////////////////
PrivateList::PrivateList()
{
_numItems = 0;
}
PrivateList::~PrivateList() {}
void PrivateList::init(Widget parent, char* title, char* usr, ConfDoc* confdoc)
{
Arg args[5]; // make sure this is large enough
char buf[16];
// set the pointer to the ConfDoc
_confdoc = confdoc;
// set the user this channel is for
strcpy(_user, usr);
// build the widgets
strcpy(buf, title);
strcat(buf, "Dialog");
_dWidget = XmCreateSelectionDialog(parent, buf, NULL, 0);
XtAddCallback(_dWidget, XmNokCallback,
(XtCallbackProc)&PrivateList::closeCB,
(XtPointer)this);
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_LIST));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_TEXT));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_SELECTION_LABEL));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_APPLY_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmSelectionBoxGetChild(_dWidget, XmDIALOG_HELP_BUTTON));
// create the form, that all the widgets will go in.
strcpy(buf, title);
strcat(buf, "Form");
Widget form = XmCreateForm(_dWidget, buf, NULL, 0);
XtManageChild(form);
// create a frame for the text input area
int n = 0;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
Widget privateFrame = XmCreateFrame(form, "privateFrame", args, n);
XtManageChild(privateFrame);
// create a text input area
n = 0;
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
Widget privateForm = XmCreateForm(privateFrame, "private2Form", args, n);
XtManageChild(privateForm);
// create the text input prompt
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
Widget privatePrompt = XmCreateText(privateForm, "privatePrompt", args, n);
XtManageChild(privatePrompt);
XmTextSetString(privatePrompt, "msg>");
// create the text input field
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNleftWidget, privatePrompt); n++;
_privateText = XmCreateText(privateForm, "privateText", args, n);
XtManageChild(_privateText);
XtAddCallback(_privateText, XmNactivateCallback,
(XtCallbackProc)&PrivateList::sendCB,
(XtPointer)_confdoc);
}
void PrivateList::closeCB(Widget, XtPointer clientData, XtPointer callData)
{
PrivateList* obj = (PrivateList*)clientData;
XtUnmanageChild(obj->_dWidget);
delete obj;
}
void PrivateList::sendCB(Widget, XtPointer clientData, XtPointer callData)
{
PrivateList* obj = (PrivateList*)clientData;
char buf[256];
char *tmp = XmTextGetString(obj->_privateText);
strcpy(buf, ":p ");
strcat(buf, obj->_user);
strcat(buf, tmp);
obj->_confdoc->sendPrivate(buf, 0);
}